import java.util.Stack;

public class Six {


    /**
     * 输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）。
     * @param head
     * @return
     */
    public int[] reversePrint(ListNode head) {

        if (head==null)
            return null;
        Stack<Integer> stack = new Stack<Integer>();
        while (head!=null){
            stack.add(head.val);
            head =head.next;
        }
        int len = stack.size();
        int[] ans = new int[len];
        for (int i=0;i<len;i++){
            ans[i] = stack.pop();
        }

        return ans;


    }
}
